package my.webservices.beans;

import static javax.persistence.GenerationType.AUTO;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * VehicleHistory represents history of a vehicle.
 * 
 * @author Nilaksh Bajpai.
 */
@Entity
@Table(name = "VEHICLE_HISTORY")
public class VehicleHistory extends BaseEntity{

	/**
	 * Serial version Uid.
	 */
	private static final long serialVersionUID = 4843073625138972968L;

	/**
	 * Identifier.
	 */
	private Long id;

	/**
	 * Event date.
	 */
	private Date eventDate;

	/**
	 * Event location.
	 */
	private String eventLocation;

	/**
	 * Odometer reading.
	 */
	private Integer reading;

	/**
	 * Source of the information.
	 */
	private String dataSource;

	/**
	 * Details about the event.
	 */
	private String details;

	/**
	 * @return
	 */
	@Id
	@GeneratedValue(strategy = AUTO)
	@Column(name = "VEH_HIST_ID")
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the eventDate
	 */
	@Column(name = "EVENT_DATE", nullable = false)
	public Date getEventDate() {
		return eventDate;
	}

	/**
	 * @param eventDate
	 *            the eventDate to set
	 */
	public void setEventDate(Date eventDate) {
		this.eventDate = eventDate;
	}

	/**
	 * @return the eventLocation
	 */
	@Column(name = "EVENT_LOCATION", nullable = false)
	public String getEventLocation() {
		return eventLocation;
	}

	/**
	 * @param eventLocation
	 *            the eventLocation to set
	 */
	public void setEventLocation(String eventLocation) {
		this.eventLocation = eventLocation;
	}

	/**
	 * @return the reading
	 */
	@Column(name = "ODOMETER_READING", nullable = true)
	public Integer getReading() {
		return reading;
	}

	/**
	 * @param reading
	 *            the reading to set
	 */
	public void setReading(Integer reading) {
		this.reading = reading;
	}

	/**
	 * @return the dataSource
	 */
	@Column(name = "INFORMATION_SOURCE", nullable = true)
	public String getDataSource() {
		return dataSource;
	}

	/**
	 * @param dataSource
	 *            the dataSource to set
	 */
	public void setDataSource(String dataSource) {
		this.dataSource = dataSource;
	}

	/**
	 * @return the details
	 */
	@Column(name = "EVENT_DETAILS", nullable = true)
	public String getDetails() {
		return details;
	}

	/**
	 * @param details
	 *            the details to set
	 */
	public void setDetails(String details) {
		this.details = details;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((eventDate == null) ? 0 : eventDate.hashCode());
		result = prime * result
				+ ((eventLocation == null) ? 0 : eventLocation.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		VehicleHistory other = (VehicleHistory) obj;
		if (eventDate == null) {
			if (other.eventDate != null) {
				return false;
			}
		} else if (!eventDate.equals(other.eventDate)) {
			return false;
		}
		if (eventLocation == null) {
			if (other.eventLocation != null) {
				return false;
			}
		} else if (!eventLocation.equals(other.eventLocation)) {
			return false;
		}
		return true;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return String
				.format("VehicleHistory [id=%s, eventDate=%s, eventLocation=%s, reading=%s, dataSource=%s, details=%s]",
						id, eventDate, eventLocation, reading, dataSource,
						details);
	}

}
